package com.bahehe.hsinchubus;

import java.io.IOException;
import java.util.Date;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import android.os.AsyncTask;
import android.util.Log;

public class AsyncHttpGet extends AsyncTask<Integer, Integer, String> {
	  
	
	  public Date LastExecTime = null;
	  public int _ExecSec = -1;
	  private boolean mRun = true;
	  protected String requestStr;
	  private boolean tryagain = false;
	  private static final String TAG = "AsyncHttpGet";
	
	public AsyncHttpGet(String paramString) {
		this.requestStr = paramString;
		// TODO Auto-generated constructor stub
	}

	public void SetRequestStr(String paramString)
	{
	    this.requestStr = paramString;
	}

	@Override
	protected String doInBackground(Integer... params) {
		// TODO Auto-generated method stub
		HttpGet localHttpGet = new HttpGet(this.requestStr);
		HttpClient httpClient = new DefaultHttpClient();
		
		try {
			HttpResponse httpResponse = httpClient.execute(localHttpGet);
			if(httpResponse.getStatusLine().getStatusCode()==HttpStatus.SC_OK){
				String strResult = EntityUtils.toString(httpResponse.getEntity());
				Log.i(TAG,strResult);
			}
		} catch (ClientProtocolException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "100";
	}

	@Override
	protected void onCancelled() {
		// TODO Auto-generated method stub
		super.onCancelled();
	}

	@Override
	protected void onPostExecute(String result) {
		// TODO Auto-generated method stub
		super.onPostExecute(result);
	}

	@Override
	protected void onPreExecute() {
		// TODO Auto-generated method stub
		super.onPreExecute();
	}

	@Override
	protected void onProgressUpdate(Integer... values) {
		// TODO Auto-generated method stub
		super.onProgressUpdate(values);
	}
	
	
	
}
